package com.kfdx.dc.controller;

import com.kfdx.dc.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kfdx.dc.common.annotation.Log;
import com.kfdx.dc.common.core.controller.BaseController;
import com.kfdx.dc.common.core.domain.AjaxResult;
import com.kfdx.dc.common.enums.BusinessType;
import com.kfdx.dc.domain.DcDishInfo;
import com.kfdx.dc.service.IDcDishInfoService;
import com.kfdx.dc.common.utils.poi.ExcelUtil;
import com.kfdx.dc.common.core.page.TableDataInfo;

/**
 * 菜品信息管理Controller
 *
 * @author cx
 * @date 2024-09-23
 */
@Api("菜品信息管理")
@RestController
@RequestMapping("/dish/info")
public class DcDishInfoController extends BaseController
{
    @Autowired
    private IDcDishInfoService dcDishInfoService;

    /**
     * 查询菜品信息管理列表
     */
    @ApiOperation("查询菜品信息管理列表")
    @PreAuthorize("@ss.hasPermi('dish:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcDishInfo dcDishInfo)
    {
        startPage();
        List<DcDishInfo> list = dcDishInfoService.selectDcDishInfoList(dcDishInfo);
        return getDataTable(list);
    }

    /**
     * 导出菜品信息管理列表
     */
    @ApiOperation("导出菜品信息管理列表")
    @PreAuthorize("@ss.hasPermi('dish:info:export')")
    @Log(title = "菜品信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcDishInfo dcDishInfo)
    {
        List<DcDishInfo> list = dcDishInfoService.selectDcDishInfoList(dcDishInfo);
        ExcelUtil<DcDishInfo> util = new ExcelUtil<DcDishInfo>(DcDishInfo.class);
        util.exportExcel(response, list, "菜品信息管理数据");
    }

    /**
     * 获取菜品信息管理详细信息
     */
    @ApiOperation("获取菜品信息管理详细信息")
    @PreAuthorize("@ss.hasPermi('dish:info:query')")
    @GetMapping(value = "/{dishId}")
    public AjaxResult getInfo(@PathVariable("dishId") Long dishId)
    {
        return success(dcDishInfoService.selectDcDishInfoByDishId(dishId));
    }

    /**
     * 新增菜品信息管理
     */
    @ApiOperation("新增菜品信息管理")
    @PreAuthorize("@ss.hasPermi('dish:info:add')")
    @Log(title = "菜品信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcDishInfo dcDishInfo)
    {
        dcDishInfo.setCreateTime(DateUtils.getNowDate());
        return toAjax(dcDishInfoService.insertDcDishInfo(dcDishInfo));
    }

    /**
     * 修改菜品信息管理
     */
    @ApiOperation("修改菜品信息管理")
    @PreAuthorize("@ss.hasPermi('dish:info:edit')")
    @Log(title = "菜品信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcDishInfo dcDishInfo)
    {
        dcDishInfo.setUpdateTime(DateUtils.getNowDate());
        return toAjax(dcDishInfoService.updateDcDishInfo(dcDishInfo));
    }

    /**
     * 删除菜品信息管理
     */
    @ApiOperation("删除菜品信息管理")
    @PreAuthorize("@ss.hasPermi('dish:info:remove')")
    @Log(title = "菜品信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dishIds}")
    public AjaxResult remove(@PathVariable Long[] dishIds)
    {
        return toAjax(dcDishInfoService.deleteDcDishInfoByDishIds(dishIds));
    }
}
